package com.yanqu.road.server.cmd.activity.xiuxian;

import com.yanqu.road.entity.activity.xiuxian.config.XiuXianConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XiuXianProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.xiuxian.CrossXiuXianMgr;
import com.yanqu.road.server.manager.activity.xiuxian.activity.CrossXiuXianActivity;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;


@Cmd(code = CrossProtocol.C_CROSS_XIU_XIAN_ACK_CAMP_ENERGY, desc = "确认同步灵峰分配")
public class CrossXiuXianAckAllotMountCmd extends CrossCommand {

    private int activityId;
    private long allotId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        XiuXianProto.CrossXiuXianAckAllotMountMsg reqMsg = XiuXianProto.CrossXiuXianAckAllotMountMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        allotId = reqMsg.getCurAllotTime();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossXiuXianActivity activity = CrossXiuXianMgr.getActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_XIU_XIAN_ACTIVITY_NOT_FOUND;
            return;
        }
        XiuXianConfig config = activity.getConfig();
        if (config == null) {
            ret = GameErrorCode.E_XIU_XIAN_CONFIG_NOT_FOUND;
            return;
        }
        activity.ackMountAllotByCmd(serverId, allotId);
    }

    @Override
    public void sendData() {
    }
}
